//
//  GLFunViewController.m
//  GLFun
//
//  Created by TTKai on 11-8-23.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "GLFunViewController.h"
#import "glfunview.h"
#import "UIColor-Random.h"

@implementation GLFunViewController

@synthesize colorControl;

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
}
*/

- (void)viewDidUnload
{
	[naviBar release];
	naviBar = nil;
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)dealloc
{
	[colorControl release];
	[naviBar release];
	[super dealloc];
}

- (IBAction)changeColor:(id)sender
{
	UISegmentedControl *control = sender;
	NSInteger index = [control selectedSegmentIndex];
	
	GLFunView *glView = (GLFunView *)self.view;
	
	switch (index)
	{
		case KRedColorTab:
			glView.currentColor = [UIColor redColor];
			glView.useRandomColor = NO;
			break;
			
		case KBlueColorTab:
			glView.currentColor = [UIColor blueColor];
			glView.useRandomColor = NO;
			break;
			
		case KYellowColorTab:
			glView.currentColor = [UIColor yellowColor];
			glView.useRandomColor = NO;
			break;
			
		case KGreenColorTab:
			glView.currentColor = [UIColor greenColor];
			glView.useRandomColor = NO;
			break;
			
		case KRandomColorTab:
			glView.useRandomColor = YES;
			break;
			
		default:
			;
	}
}

- (IBAction)changeShape:(id)sender
{
	UISegmentedControl *control = sender;
	[(GLFunView *)self.view setShapeType:[control selectedSegmentIndex]];
	
	if ([control selectedSegmentIndex] == KImageShape)
	{
		colorControl.hidden = YES;
		naviBar.hidden = YES;
	}
	else
	{
		colorControl.hidden = NO;
		naviBar.hidden = NO;
	}
}


@end
